package com.zjp.reflect;

import com.zjp.entity.User;

/**
 * @author: zjp
 * @date: 2023-12-01
 * @description: 演示获取Class对象的三种方式
 */
public class Test1_GetClass {
    public static void main(String[] args) throws ClassNotFoundException {
        // 方式一：通过 类名.class 方式获取
        Class<User> c1 = User.class;
        System.out.println(c1.getName()); // com.zjp.entity.User
        System.out.println(c1.getSimpleName()); // User
        System.out.println(c1.getCanonicalName()); // com.zjp.entity.User
        System.out.println(c1.getTypeName()); // com.zjp.entity.User

        // 方式二：通过 Class.forName() 获取
        Class<?> c2 = Class.forName("com.zjp.entity.User");
        System.out.println(c1 == c2); // true

        // 方式三：通过 对象.getClass() 获取
//        User user = new User();
//        Class<? extends User> c3 = user.getClass();
//        System.out.println(c1 == c3); // true

    }
}
